package com.example.it.looker.presenter;

import com.example.it.looker.model.datasource.ImageDataSource;
import com.example.it.looker.model.entity.Image;
import com.example.it.looker.presenter.contact.ImageContact;

import java.util.List;

/**
 * Created by 鲁迅认识的那只猹 on 9/4/2017 7:21 PM.
 * Emial 1258730808@qq.com
 * Desc:
 */

public class ImagePresenter implements ImageContact.ImagePresenter {

    private ImageContact.ImageView imageView;
    private ImageDataSource dataSource;

    public ImagePresenter(ImageContact.ImageView imageView, ImageDataSource dataSource) {
        this.imageView = imageView;
        this.dataSource = dataSource;
    }

    /**
     * 获取必应美图信息，并发送的UI
     */
    @Override
    public void loadData() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                imageView.loading();
                List<Image> imageList = dataSource.load();
                imageView.loadedData(imageList);
            }
        }).start();
    }

    @Override
    public void onDestroy() {
        this.imageView = null;
    }
}
